home *** CD-ROM | disk | FTP | other *** search
/ Erotic Games: Memory / Erotic Games: Memory.iso / mac / air_installers / AdobeAIR.exe / setup.swf / scripts / mx / collections / XMLListAdapter.as < prev    next >
Text File  |  2009-02-12  |  12KB  |  382 lines

  1. package mx.collections
  2. {
  3.    import flash.events.EventDispatcher;
  4.    import flash.utils.getQualifiedClassName;
  5.    import mx.core.mx_internal;
  6.    import mx.events.CollectionEvent;
  7.    import mx.events.CollectionEventKind;
  8.    import mx.events.PropertyChangeEvent;
  9.    import mx.events.PropertyChangeEventKind;
  10.    import mx.resources.IResourceManager;
  11.    import mx.resources.ResourceManager;
  12.    import mx.utils.IXMLNotifiable;
  13.    import mx.utils.UIDUtil;
  14.    import mx.utils.XMLNotifier;
  15.    
  16.    use namespace mx_internal;
  17.    
  18.    public class XMLListAdapter extends EventDispatcher implements IList, IXMLNotifiable
  19.    {
  20.       
  21.       mx_internal static const VERSION:String = "3.0.0.0";
  22.        
  23.       
  24.       private var uidCounter:int = 0;
  25.       
  26.       private var _dispatchEvents:int = 0;
  27.       
  28.       private var _busy:int = 0;
  29.       
  30.       private var seedUID:String;
  31.       
  32.       private var _source:XMLList;
  33.       
  34.       private var resourceManager:IResourceManager;
  35.       
  36.       public function XMLListAdapter(param1:XMLList = null)
  37.       {
  38.          resourceManager = ResourceManager.getInstance();
  39.          super();
  40.          disableEvents();
  41.          this.source = param1;
  42.          enableEvents();
  43.       }
  44.       
  45.       public function setItemAt(param1:Object, param2:int) : Object
  46.       {
  47.          var _loc4_:String = null;
  48.          var _loc5_:CollectionEvent = null;
  49.          var _loc6_:PropertyChangeEvent = null;
  50.          if(param2 < 0 || param2 >= length)
  51.          {
  52.             _loc4_ = resourceManager.getString("collections","outOfBounds",[param2]);
  53.             throw new RangeError(_loc4_);
  54.          }
  55.          var _loc3_:Object = source[param2];
  56.          source[param2] = param1;
  57.          stopTrackUpdates(_loc3_);
  58.          startTrackUpdates(param1,seedUID + uidCounter.toString());
  59.          ++uidCounter;
  60.          if(_dispatchEvents == 0)
  61.          {
  62.             (_loc5_ = new CollectionEvent(CollectionEvent.COLLECTION_CHANGE)).kind = CollectionEventKind.REPLACE;
  63.             (_loc6_ = new PropertyChangeEvent(PropertyChangeEvent.PROPERTY_CHANGE)).kind = PropertyChangeEventKind.UPDATE;
  64.             _loc6_.oldValue = _loc3_;
  65.             _loc6_.newValue = param1;
  66.             _loc5_.location = param2;
  67.             _loc5_.items.push(_loc6_);
  68.             dispatchEvent(_loc5_);
  69.          }
  70.          return _loc3_;
  71.       }
  72.       
  73.       protected function startTrackUpdates(param1:Object, param2:String) : void
  74.       {
  75.          XMLNotifier.getInstance().watchXML(param1,this,param2);
  76.       }
  77.       
  78.       public function removeAll() : void
  79.       {
  80.          var _loc1_:int = 0;
  81.          var _loc2_:CollectionEvent = null;
  82.          if(length > 0)
  83.          {
  84.             _loc1_ = length - 1;
  85.             while(_loc1_ >= 0)
  86.             {
  87.                stopTrackUpdates(source[_loc1_]);
  88.                delete source[_loc1_];
  89.                _loc1_--;
  90.             }
  91.             if(_dispatchEvents == 0)
  92.             {
  93.                _loc2_ = new CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
  94.                _loc2_.kind = CollectionEventKind.RESET;
  95.                dispatchEvent(_loc2_);
  96.             }
  97.          }
  98.       }
  99.       
  100.       protected function itemUpdateHandler(param1:PropertyChangeEvent) : void
  101.       {
  102.          var _loc2_:CollectionEvent = null;
  103.          if(_dispatchEvents == 0)
  104.          {
  105.             _loc2_ = new CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
  106.             _loc2_.kind = CollectionEventKind.UPDATE;
  107.             _loc2_.items.push(param1);
  108.             dispatchEvent(_loc2_);
  109.          }
  110.       }
  111.       
  112.       public function getItemIndex(param1:Object) : int
  113.       {
  114.          var _loc2_:int = 0;
  115.          var _loc3_:int = 0;
  116.          var _loc4_:Object = null;
  117.          if(param1 is XML && source.contains(XML(param1)))
  118.          {
  119.             _loc2_ = length;
  120.             _loc3_ = 0;
  121.             while(_loc3_ < _loc2_)
  122.             {
  123.                if((_loc4_ = source[_loc3_]) === param1)
  124.                {
  125.                   return _loc3_;
  126.                }
  127.                _loc3_++;
  128.             }
  129.          }
  130.          return -1;
  131.       }
  132.       
  133.       public function removeItemAt(param1:int) : Object
  134.       {
  135.          var _loc3_:String = null;
  136.          var _loc4_:CollectionEvent = null;
  137.          if(param1 < 0 || param1 >= length)
  138.          {
  139.             _loc3_ = resourceManager.getString("collections","outOfBounds",[param1]);
  140.             throw new RangeError(_loc3_);
  141.          }
  142.          setBusy();
  143.          var _loc2_:Object = source[param1];
  144.          delete source[param1];
  145.          stopTrackUpdates(_loc2_);
  146.          if(_dispatchEvents == 0)
  147.          {
  148.             (_loc4_ = new CollectionEvent(CollectionEvent.COLLECTION_CHANGE)).kind = CollectionEventKind.REMOVE;
  149.             _loc4_.location = param1;
  150.             _loc4_.items.push(_loc2_);
  151.             dispatchEvent(_loc4_);
  152.          }
  153.          clearBusy();
  154.          return _loc2_;
  155.       }
  156.       
  157.       public function addItem(param1:Object) : void
  158.       {
  159.          addItemAt(param1,length);
  160.       }
  161.       
  162.       public function get source() : XMLList
  163.       {
  164.          return _source;
  165.       }
  166.       
  167.       public function toArray() : Array
  168.       {
  169.          var _loc1_:XMLList = source;
  170.          var _loc2_:int = _loc1_.length();
  171.          var _loc3_:Array = [];
  172.          var _loc4_:int = 0;
  173.          while(_loc4_ < _loc2_)
  174.          {
  175.             _loc3_[_loc4_] = _loc1_[_loc4_];
  176.             _loc4_++;
  177.          }
  178.          return _loc3_;
  179.       }
  180.       
  181.       protected function disableEvents() : void
  182.       {
  183.          --_dispatchEvents;
  184.       }
  185.       
  186.       public function xmlNotification(param1:Object, param2:String, param3:Object, param4:Object, param5:Object) : void
  187.       {
  188.          var _loc6_:String = null;
  189.          var _loc7_:Object = null;
  190.          var _loc8_:Object = null;
  191.          var _loc9_:* = undefined;
  192.          var _loc10_:* = undefined;
  193.          if(param1 === param3)
  194.          {
  195.             switch(param2)
  196.             {
  197.                case "attributeAdded":
  198.                   _loc6_ = "@" + String(param4);
  199.                   _loc8_ = param5;
  200.                   break;
  201.                case "attributeChanged":
  202.                   _loc6_ = "@" + String(param4);
  203.                   _loc7_ = param5;
  204.                   _loc8_ = param3[_loc6_];
  205.                   break;
  206.                case "attributeRemoved":
  207.                   _loc6_ = "@" + String(param4);
  208.                   _loc7_ = param5;
  209.                   break;
  210.                case "nodeAdded":
  211.                   _loc6_ = param4.localName();
  212.                   _loc8_ = param4;
  213.                   break;
  214.                case "nodeChanged":
  215.                   _loc6_ = param4.localName();
  216.                   _loc7_ = param5;
  217.                   _loc8_ = param4;
  218.                   break;
  219.                case "nodeRemoved":
  220.                   _loc6_ = param4.localName();
  221.                   _loc7_ = param4;
  222.                   break;
  223.                case "textSet":
  224.                   _loc6_ = String(param4);
  225.                   _loc8_ = String(param3[_loc6_]);
  226.                   _loc7_ = param5;
  227.             }
  228.          }
  229.          else if(param2 == "textSet")
  230.          {
  231.             if((_loc9_ = param3.parent()) != undefined)
  232.             {
  233.                if((_loc10_ = _loc9_.parent()) === param1)
  234.                {
  235.                   _loc6_ = _loc9_.name().toString();
  236.                   _loc8_ = param4;
  237.                   _loc7_ = param5;
  238.                }
  239.             }
  240.          }
  241.          itemUpdated(param1,_loc6_,_loc7_,_loc8_);
  242.       }
  243.       
  244.       public function addItemAt(param1:Object, param2:int) : void
  245.       {
  246.          var _loc3_:String = null;
  247.          var _loc4_:CollectionEvent = null;
  248.          if(param2 < 0 || param2 > length)
  249.          {
  250.             _loc3_ = resourceManager.getString("collections","outOfBounds",[param2]);
  251.             throw new RangeError(_loc3_);
  252.          }
  253.          if(!(param1 is XML) && !(param1 is XMLList && param1.length() == 1))
  254.          {
  255.             _loc3_ = resourceManager.getString("collections","invalidType");
  256.             throw new Error(_loc3_);
  257.          }
  258.          setBusy();
  259.          if(param2 == 0)
  260.          {
  261.             source[0] = length > 0 ? param1 + source[0] : param1;
  262.          }
  263.          else
  264.          {
  265.             source[param2 - 1] += param1;
  266.          }
  267.          startTrackUpdates(param1,seedUID + uidCounter.toString());
  268.          ++uidCounter;
  269.          if(_dispatchEvents == 0)
  270.          {
  271.             (_loc4_ = new CollectionEvent(CollectionEvent.COLLECTION_CHANGE)).kind = CollectionEventKind.ADD;
  272.             _loc4_.items.push(param1);
  273.             _loc4_.location = param2;
  274.             dispatchEvent(_loc4_);
  275.          }
  276.          clearBusy();
  277.       }
  278.       
  279.       public function getItemAt(param1:int, param2:int = 0) : Object
  280.       {
  281.          var _loc3_:String = null;
  282.          if(param1 < 0 || param1 >= length)
  283.          {
  284.             _loc3_ = resourceManager.getString("collections","outOfBounds",[param1]);
  285.             throw new RangeError(_loc3_);
  286.          }
  287.          return source[param1];
  288.       }
  289.       
  290.       override public function toString() : String
  291.       {
  292.          if(source)
  293.          {
  294.             return source.toString();
  295.          }
  296.          return getQualifiedClassName(this);
  297.       }
  298.       
  299.       public function get length() : int
  300.       {
  301.          return source.length();
  302.       }
  303.       
  304.       public function itemUpdated(param1:Object, param2:Object = null, param3:Object = null, param4:Object = null) : void
  305.       {
  306.          var _loc5_:PropertyChangeEvent;
  307.          (_loc5_ = new PropertyChangeEvent(PropertyChangeEvent.PROPERTY_CHANGE)).kind = PropertyChangeEventKind.UPDATE;
  308.          _loc5_.source = param1;
  309.          _loc5_.property = param2;
  310.          _loc5_.oldValue = param3;
  311.          _loc5_.newValue = param4;
  312.          itemUpdateHandler(_loc5_);
  313.       }
  314.       
  315.       protected function stopTrackUpdates(param1:Object) : void
  316.       {
  317.          XMLNotifier.getInstance().unwatchXML(param1,this);
  318.       }
  319.       
  320.       private function clearBusy() : void
  321.       {
  322.          ++_busy;
  323.          if(_busy > 0)
  324.          {
  325.             _busy = 0;
  326.          }
  327.       }
  328.       
  329.       public function set source(param1:XMLList) : void
  330.       {
  331.          var _loc2_:int = 0;
  332.          var _loc3_:int = 0;
  333.          var _loc4_:CollectionEvent = null;
  334.          if(_source && _source.length())
  335.          {
  336.             _loc3_ = _source.length();
  337.             _loc2_ = 0;
  338.             while(_loc2_ < _loc3_)
  339.             {
  340.                stopTrackUpdates(_source[_loc2_]);
  341.                _loc2_++;
  342.             }
  343.          }
  344.          _source = !!param1 ? param1 : XMLList(new XMLList(""));
  345.          seedUID = UIDUtil.createUID();
  346.          uidCounter = 0;
  347.          _loc3_ = _source.length();
  348.          _loc2_ = 0;
  349.          while(_loc2_ < _loc3_)
  350.          {
  351.             startTrackUpdates(_source[_loc2_],seedUID + uidCounter.toString());
  352.             ++uidCounter;
  353.             _loc2_++;
  354.          }
  355.          if(_dispatchEvents == 0)
  356.          {
  357.             (_loc4_ = new CollectionEvent(CollectionEvent.COLLECTION_CHANGE)).kind = CollectionEventKind.RESET;
  358.             dispatchEvent(_loc4_);
  359.          }
  360.       }
  361.       
  362.       public function busy() : Boolean
  363.       {
  364.          return _busy != 0;
  365.       }
  366.       
  367.       private function setBusy() : void
  368.       {
  369.          --_busy;
  370.       }
  371.       
  372.       protected function enableEvents() : void
  373.       {
  374.          ++_dispatchEvents;
  375.          if(_dispatchEvents > 0)
  376.          {
  377.             _dispatchEvents = 0;
  378.          }
  379.       }
  380.    }
  381. }
  382.